<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>移动文章-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/resource/backend/css/font.css">
    <link rel="stylesheet" href="/resource/backend/css/weadmin.css">
    <script src="/resource/backend/lib/layui/layui.js" charset="utf-8"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="weadmin-body">
    <form action="" method="post" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">移动到</label>
            <div class="layui-input-block">
                <select name="channel_id">
                    <option value="" data-level="0">-请选择栏目-</option>
                    ${range $key, $item := .channelModelTree}$
                    <option value="${$item.Id}$" data-level="${$item.Level}$">
                        ${$item.Name}$
                    </option>
                    ${end}$
                </select>
            </div>
        </div>
        <div class="layui-input-inline">
            <input type="hidden" name="str_ids" value="${.strIds}$">
            <button class="layui-btn" lay-submit="" lay-filter="move">移动文章</button>
        </div>
    </form>
</div>

<script type="text/javascript">

    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;
        //监听提交
        form.on('submit(move)', function (data) {
            //console.log($('input:checked').length);
            console.log(data.field);
            $.post('${ backend_api_url `/article/move` }$', data.field, function (res) {
                if (res.code === 0) {
                    //移动成功
                    layer.msg(res.message, {
                        icon: 6
                        , time: 1000
                    }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        //刷新父级页面
                        //parent.location.reload();
                        //模拟点击父级页面的搜索按钮，以达到动态加载效果，并保留所选的栏目select不变
                        $('#reload', parent.document).trigger('click');
                    });
                } else {
                    //修改失败
                    layer.msg(res.message, {
                            'icon': 5
                            , time: 1000
                        }
                    );
                }
            });
            return false;
        });
    });

</script>
</body>

</html>